export default function() {
    return {
        data() {
            return {}
        },
        methods: {
            sizeChange(val) {
                this.page.currentPage = 1;
                this.page.pageSize = val;
                this.getList();
            },
            currentChange(val) {
                this.page.currentPage = val;
                this.getList();
            },
            refreshChange() {
                this.getList();
            },
            rowDel(from, index) {
                if (from.id) {
                    this.$confirm("此操作为永久删除, 是否继续?", "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                        callback: async action => {
                            if(action == 'confirm'){
                                const res = await this._delObj(from);
                                if (res.data.code == 0) {
                                    this.records.every((item, index) => {
                                        if (item.id == from.id) {
                                            this.records.splice(index, 1);
                                            this.page.total--;
                                            this.$message({
                                                type: "success",
                                                message: "删除成功!"
                                            });
                                            if(res.request.responseURL.indexOf('wall/upsSuppliers') !== -1){ //如果是删除上游商信息时
                                                this.$store.dispatch("GetAllUpsSuppliersInfo"); //刷新vuex中的上游商信息
                                            }
                                            if(res.request.responseURL.indexOf('wall/product') !== -1){ //如果是删除上游商信息时
                                                this.$store.dispatch("GetProductsInfo"); //刷新vuex中的上游商信息
                                            }
                                            if(res.request.responseURL.indexOf('wall/requestInfo') !== -1){ //如果是删除上游商信息时
                                                this.$store.dispatch("GetAllRequesInfo"); //刷新vuex中的请求信息
                                            }
                                            return false;
                                        } else {
                                            return true;
                                        }
                                    });
                                }
                            }else {
                                this.$message({
                                    type: "info",
                                    message: "已取消删除"
                                });
                            }
                        }
                    });
                }
            },
            searchChange(params){
                this.searchParams = params;
                this.getList();
            },
            filterUpsId(val){ //过滤上游商
                let tempStr = '';
                this.upsSuppliersInfo.forEach(item => {
                    if(item.value === val){
                        tempStr = item.label;
                    }
                });
                return tempStr;
            },
            filtersProductId(val) { //过滤产品名
                let tempStr = '';
                this.productsInfo.forEach(item => {
                    if(item.value === val){
                        tempStr = item.label;
                    }
                });
                return tempStr;
            },
            filtersRequest(val) { //过滤请求名
                let tempStr = '';
                this.allRequesInfo.forEach(item => {
                    if(item.value === val){
                        tempStr = item.label;
                    }
                });
                return tempStr;
            },
            filterUserId(val) { //过滤下游名称
                let tempStr = '';
                this.downSuppliersInfo.forEach(item => {
                    if(item.value === val){
                        tempStr = item.label;
                    }
                });
                return tempStr;
            },
            filterFontendParamsTypeList(val) { //过滤下游名称
                let tempStr = '';
                this.frontendPramasTypeList.forEach(item => {
                    if(item.value === val){
                        tempStr = item.label;
                    }
                });
                return tempStr;
            },
            filterTaskTypeList(val) { //过滤任务类型
                let tempStr = '';
                this.taskStateList.forEach(item => {
                    if(item.value === val){
                        tempStr = item.label;
                    }
                });
                return tempStr;
            },
            filterGroupId(val) { //过滤用户组Id
                let tempStr = '';
                this.groupIdList.forEach(item => {
                    if(item.value === val){
                        tempStr = item.label;
                    }
                });
                return tempStr;
            },
            filterBusiness(val) { //过滤商务
                let tempStr = '';
                this.businessInfo.forEach(item => {
                    if(item.value == val){
                        tempStr = item.label;
                    }
                });
                return tempStr || '无';
            },
        },
        filters: {
            handleStringSaveFour(val){
                return val.length < 4 ? val : val.substring(0,5)+"**"
            },
            handleStringSaveEight(val){
                return val.length < 8 ? val : val.substring(0,8)+"**"
            }
        }
    }
}